package com.sina.weibo;

import android.content.ContentResolver;
import android.graphics.Bitmap;
import android.graphics.Bitmap.CompressFormat;
import android.graphics.BitmapFactory;
import android.graphics.BitmapFactory.Options;
import android.net.Uri;
import java.io.BufferedInputStream;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import sudroid.android.CleanUtils;
import sudroid.android.FileUtil;

final class ImageLoadingHelper
{
  private static int[] photoSizes;
  private static BitmapFactory.Options thumbnailOpts = new BitmapFactory.Options();
  private EditActivity activity;
  private String defaultDraftPath;
  private String defaultTempPath;
  private File picfile;

  static
  {
    photoSizes = new int[] { 2048, 1024, 512 };
  }

  ImageLoadingHelper(EditActivity paramEditActivity)
  {
    this.activity = paramEditActivity;
    String str1 = String.valueOf(paramEditActivity.getFilesDir().getAbsolutePath());
    String str2 = str1 + "/new_blog/bitmap_temp.jpg";
    this.defaultTempPath = str2;
    String str3 = String.valueOf(paramEditActivity.getFilesDir().getAbsolutePath());
    String str4 = str3 + "/draft/bitmap_temp.jpg";
    this.defaultDraftPath = str4;
    String str5 = this.defaultTempPath;
    File localFile = new File(str5);
    this.picfile = localFile;
    FileUtil.makesureParentExist(this.picfile);
    thumbnailOpts.inJustDecodeBounds = 0;
    thumbnailOpts.inSampleSize = 4;
  }

  public static boolean isSame(File paramFile1, File paramFile2)
  {
    long l1 = paramFile1.length();
    long l2 = paramFile2.length();
    int i;
    if (l1 != l2)
      i = 0;
    while (true)
    {
      return i;
      try
      {
        FileInputStream localFileInputStream1 = new FileInputStream(paramFile1);
        FileInputStream localFileInputStream2 = new FileInputStream(paramFile2);
        boolean bool = isSame(localFileInputStream1, localFileInputStream2);
        i = bool;
      }
      catch (FileNotFoundException localFileNotFoundException)
      {
        Utils.loge(localFileNotFoundException);
        i = 0;
      }
    }
  }

  public static boolean isSame(InputStream paramInputStream1, InputStream paramInputStream2)
  {
    paramInputStream1 = FileUtil.makeInputBuffered(paramInputStream1);
    paramInputStream2 = FileUtil.makeInputBuffered(paramInputStream2);
    try
    {
      int i = paramInputStream1.read();
      int j = paramInputStream2.read();
      int k = j;
      if (i != k)
      {
        boolean bool1 = CleanUtils.closeStream(paramInputStream1);
        boolean bool2 = CleanUtils.closeStream(paramInputStream2);
      }
      for (int m = 0; ; m = 1)
      {
        return m;
        if (i != -1)
          break;
        boolean bool3 = CleanUtils.closeStream(paramInputStream1);
        boolean bool4 = CleanUtils.closeStream(paramInputStream2);
      }
    }
    catch (Exception localException)
    {
      while (true)
      {
        Utils.loge(localException);
        boolean bool5 = CleanUtils.closeStream(paramInputStream1);
        boolean bool6 = CleanUtils.closeStream(paramInputStream2);
      }
    }
    finally
    {
      boolean bool7 = CleanUtils.closeStream(paramInputStream1);
      boolean bool8 = CleanUtils.closeStream(paramInputStream2);
    }
    throw localObject;
  }

  public static boolean isSame(String paramString1, String paramString2)
  {
    File localFile1 = new File(paramString1);
    File localFile2 = new File(paramString2);
    return isSame(localFile1, localFile2);
  }

  private void revitionImageSize()
    throws IOException
  {
    String str = SettingsPref.getUploadImageSize(this.activity);
    String[] arrayOfString = SettingsPref.getUploadImageSizeSet(this.activity);
    int i = search(arrayOfString, str);
    Utils.logd("\t currentUploadSize:" + str + "\t index:" + i);
    int j = photoSizes[i];
    revitionImageSize(j);
  }

  private void revitionImageSize(int paramInt)
    throws IOException
  {
    if (paramInt <= 0)
      throw new IllegalArgumentException("size must be greater than 0!");
    if (!FileUtil.doesExisted(this.picfile))
    {
      FileNotFoundException localFileNotFoundException = new java/io/FileNotFoundException;
      if (this.picfile == null);
      for (String str = "null"; ; str = this.picfile.getAbsolutePath())
      {
        localFileNotFoundException.<init>(str);
        throw localFileNotFoundException;
      }
    }
    if (!verifyBitmap(this.picfile))
      throw new IOException("");
    File localFile1 = this.picfile;
    FileInputStream localFileInputStream1 = new FileInputStream(localFile1);
    BitmapFactory.Options localOptions = new BitmapFactory.Options();
    localOptions.inJustDecodeBounds = 1;
    Bitmap localBitmap1 = BitmapFactory.decodeStream(localFileInputStream1, null, localOptions);
    boolean bool1 = CleanUtils.closeStream(localFileInputStream1);
    int i = 0;
    Bitmap localBitmap2;
    while (true)
    {
      if ((localOptions.outWidth >> i <= paramInt) && (localOptions.outHeight >> i <= paramInt))
      {
        int j = i;
        StringBuilder localStringBuilder1 = new StringBuilder("\t opts.outWidth:");
        int k = localOptions.outWidth;
        StringBuilder localStringBuilder2 = localStringBuilder1.append(k).append("\t opts.outHeight:");
        int m = localOptions.outHeight;
        Utils.logd(m);
        StringBuilder localStringBuilder3 = new StringBuilder("\t rate:");
        double d1 = j;
        double d2 = Math.pow(2.0D, d1);
        Utils.logd(d2);
        File localFile2 = this.picfile;
        FileInputStream localFileInputStream2 = new FileInputStream(localFile2);
        double d3 = j;
        int n = (int)Math.pow(2.0D, d3);
        localOptions.inSampleSize = n;
        localOptions.inJustDecodeBounds = 0;
        localBitmap2 = BitmapFactory.decodeStream(localFileInputStream2, null, localOptions);
        boolean bool2 = CleanUtils.closeStream(localFileInputStream2);
        if (localBitmap2 != null)
          break;
        throw new IOException("Bitmap decode error!");
      }
      i += 1;
    }
    boolean bool3 = FileUtil.deleteDependon(this.picfile);
    FileUtil.makesureFileExist(this.picfile);
    File localFile3 = this.picfile;
    FileOutputStream localFileOutputStream = new FileOutputStream(localFile3);
    Bitmap.CompressFormat localCompressFormat = Bitmap.CompressFormat.JPEG;
    boolean bool4 = localBitmap2.compress(localCompressFormat, 75, localFileOutputStream);
    boolean bool5 = CleanUtils.closeStream(localFileOutputStream);
    localBitmap2.recycle();
  }

  private int search(String[] paramArrayOfString, String paramString)
  {
    int i = 0;
    int j = paramArrayOfString.length;
    while (true)
    {
      if (i >= j);
      for (int k = -1; ; k = i)
      {
        return k;
        String str = paramArrayOfString[i];
        if (!paramString.equals(str))
          break;
      }
      i += 1;
    }
  }

  private static boolean verifyBitmap(File paramFile)
  {
    try
    {
      boolean bool1 = verifyBitmap(new FileInputStream(paramFile));
      bool2 = bool1;
      return bool2;
    }
    catch (FileNotFoundException localFileNotFoundException)
    {
      while (true)
      {
        Utils.loge(localFileNotFoundException);
        boolean bool2 = false;
      }
    }
  }

  private static boolean verifyBitmap(InputStream paramInputStream)
  {
    BitmapFactory.Options localOptions = new BitmapFactory.Options();
    localOptions.inJustDecodeBounds = 1;
    if ((paramInputStream instanceof BufferedInputStream))
    {
      Bitmap localBitmap = BitmapFactory.decodeStream(paramInputStream, null, localOptions);
      boolean bool = CleanUtils.closeStream(paramInputStream);
      StringBuilder localStringBuilder1 = new StringBuilder("\t outHeight:");
      int i = localOptions.outHeight;
      StringBuilder localStringBuilder2 = localStringBuilder1.append(i).append("\t outWidth:");
      int j = localOptions.outWidth;
      Utils.logd(j);
      if ((localOptions.outHeight <= 0) || (localOptions.outWidth <= 0))
        break label115;
    }
    label115: for (int k = 1; ; k = 0)
    {
      return k;
      paramInputStream = new BufferedInputStream(paramInputStream);
      break;
    }
  }

  private static boolean verifyBitmap(String paramString)
  {
    try
    {
      boolean bool1 = verifyBitmap(new FileInputStream(paramString));
      bool2 = bool1;
      return bool2;
    }
    catch (FileNotFoundException localFileNotFoundException)
    {
      while (true)
      {
        Utils.loge(localFileNotFoundException);
        boolean bool2 = false;
      }
    }
  }

  private static boolean verifyBitmap(byte[] paramArrayOfByte)
  {
    return verifyBitmap(new ByteArrayInputStream(paramArrayOfByte));
  }

  Bitmap createThumbnail()
  {
    if (!hasBitmap())
      throw new IllegalStateException("There is no pic!");
    String str = getTempPath();
    BitmapFactory.Options localOptions = thumbnailOpts;
    return BitmapFactory.decodeFile(str, localOptions);
  }

  boolean deleteDraft()
  {
    Utils.logd("删除图片缓存");
    return FileUtil.deleteDependon(this.defaultDraftPath);
  }

  boolean doesDraftExist()
  {
    return FileUtil.doesExisted(this.defaultDraftPath);
  }

  boolean equalDraft()
  {
    String str1 = this.defaultTempPath;
    String str2 = this.defaultDraftPath;
    return isSame(str1, str2);
  }

  String getTempPath()
  {
    return this.picfile.getAbsolutePath();
  }

  /** @deprecated */
  boolean hasBitmap()
  {
    monitorenter;
    try
    {
      boolean bool1 = FileUtil.doesExisted(this.picfile);
      boolean bool2 = bool1;
      monitorexit;
      return bool2;
    }
    finally
    {
      localObject = finally;
      monitorexit;
    }
    throw localObject;
  }

  /** @deprecated */
  void importBitmapFile(Uri paramUri)
  {
    monitorenter;
    while (true)
    {
      try
      {
        reset();
        FileUtil.makesureFileExist(this.picfile);
        try
        {
          if (!paramUri.getScheme().equals("content"))
            continue;
          InputStream localInputStream = this.activity.getContentResolver().openInputStream(paramUri);
          File localFile1 = this.picfile;
          FileOutputStream localFileOutputStream1 = new FileOutputStream(localFile1);
          FileUtil.copy(localInputStream, localFileOutputStream1);
          if (verifyBitmap(this.picfile))
            break label176;
          boolean bool1 = FileUtil.deleteDependon(this.picfile);
          throw new IOException("\t 不是有效图片格式");
        }
        catch (Exception localException)
        {
          Utils.loge(localException);
          reset();
        }
        return;
        if (!paramUri.getScheme().equals("file"))
          continue;
        String str = paramUri.getPath();
        FileInputStream localFileInputStream = new FileInputStream(str);
        File localFile2 = this.picfile;
        FileOutputStream localFileOutputStream2 = new FileOutputStream(localFile2);
        FileUtil.copy(localFileInputStream, localFileOutputStream2);
        boolean bool2 = FileUtil.deleteDependon(paramUri.getPath());
        continue;
      }
      finally
      {
        monitorexit;
      }
      label176: revitionImageSize();
    }
  }

  void loadDraft()
  {
    try
    {
      String str1 = this.defaultDraftPath;
      String str2 = this.defaultTempPath;
      FileUtil.copy(str1, str2);
      this.activity.displayInsertBitmap();
      Utils.logd("\t 读取图片缓存成功");
      return;
    }
    catch (IOException localIOException)
    {
      while (true)
        Utils.loge(localIOException);
    }
  }

  /** @deprecated */
  void reset()
  {
    monitorenter;
    try
    {
      boolean bool = FileUtil.deleteDependon(this.picfile);
      monitorexit;
      return;
    }
    finally
    {
      localObject = finally;
      monitorexit;
    }
    throw localObject;
  }

  boolean saveDraft()
  {
    try
    {
      boolean bool = FileUtil.deleteDependon(this.defaultDraftPath);
      FileUtil.makesureFileExist(this.defaultDraftPath);
      String str1 = this.defaultTempPath;
      String str2 = this.defaultDraftPath;
      FileUtil.copy(str1, str2);
      Utils.logd("\t 存入图片缓存成功");
      i = 1;
      return i;
    }
    catch (IOException localIOException)
    {
      while (true)
      {
        Utils.loge(localIOException);
        int i = 0;
      }
    }
  }
}

/* Location:           D:\Program Files\eclipse\apktool-r01-3\新浪微博\classes.dex.dex2jar.jar
 * Qualified Name:     com.sina.weibo.ImageLoadingHelper
 * JD-Core Version:    0.6.0
 */